#!/bin/bash
nginx_home=/opt/module/nginx
logger_home=/home/atguigu/gmall_0722
jar=gmall-logger-0.0.1-SNAPSHOT.jar
case $1 in
"start")
   echo "在hadoop162上启动nginx"
   if [ -z "$(ps -ef | awk '/nginx/ && !/awk/ {print $0}')" ]; then
        $nginx_home/sbin/nginx
   else
        echo "nginx 已经启动, 不用重复启"
   fi
   for host in hadoop162 hadoop163 hadoop164 ; do
       echo "在 $host 上启动日志服务器"
       ssh $host "cd $logger_home; nohup java -jar $logger_home/$jar >$logger_home/tmp.log 2>&1  &"
   done

   ;;
"stop")
    echo "在hadoop162上启动nginx"
    $nginx_home/sbin/nginx -s stop
    for host in hadoop162 hadoop163 hadoop164 ; do
       echo "在 $host 上停止日志服务器"
       ssh $host "jps | awk '/gmall-logger/ {print \$1}' | xargs kill -9"
   done
   ;;
*)
    echo "你启动的姿势不对"
    echo "  logger.sh start 启动nginx和日志服务器集群"
    echo "  logger.sh stop  停止nginx和日志服务器集群"
   ;;
esac



